#include "sqlite_manager.h"
#include <iostream>
#include <vector>

int main() {
    // 获取SQLiteManager单例实例
    SQLiteManager& db = SQLiteManager::getInstance();
    
    // 连接数据库
    if (!db.connect("test_time_fields.db")) {
        std::cerr << "无法连接到数据库" << std::endl;
        return 1;
    }
    
    std::cout << "成功连接到数据库" << std::endl;
    
    // 创建一个测试QSO记录
    QSORecord record;
    record.date = "2024-05-20";
    record.time = "18:35";
    record.callsign = "BA1AA";
    record.band = "20M";
    record.mode = "SSB";
    record.rst_sent = "59";
    record.rst_rcvd = "59";
    record.name = "张三";
    record.qth = "北京";
    record.memo = "测试记录";
    record.log_creation_date = "2024-01-15 10:00:00";
    record.record_create_time = "2024-05-20 18:35:00";
    record.record_modify_time = "2024-05-20 19:10:00";
    
    // 插入记录
    if (db.insertQSO(record)) {
        std::cout << "成功插入QSO记录" << std::endl;
    } else {
        std::cerr << "插入QSO记录失败" << std::endl;
        return 1;
    }
    
    // 查询所有记录
    std::vector<QSORecord> records = db.getAllQSOs();
    std::cout << "查询到 " << records.size() << " 条记录" << std::endl;
    
    // 显示记录详情
    for (const auto& rec : records) {
        std::cout << "ID: " << rec.id << std::endl;
        std::cout << "Date: " << rec.date << std::endl;
        std::cout << "Time: " << rec.time << std::endl;
        std::cout << "Callsign: " << rec.callsign << std::endl;
        std::cout << "Band: " << rec.band << std::endl;
        std::cout << "Mode: " << rec.mode << std::endl;
        std::cout << "RST Sent: " << rec.rst_sent << std::endl;
        std::cout << "RST Rcvd: " << rec.rst_rcvd << std::endl;
        std::cout << "Name: " << rec.name << std::endl;
        std::cout << "QTH: " << rec.qth << std::endl;
        std::cout << "Memo: " << rec.memo << std::endl;
        std::cout << "Log Creation Date: " << rec.log_creation_date << std::endl;
        std::cout << "Record Create Time: " << rec.record_create_time << std::endl;
        std::cout << "Record Modify Time: " << rec.record_modify_time << std::endl;
        std::cout << "------------------------" << std::endl;
    }
    
    // 更新记录
    if (!records.empty()) {
        QSORecord& update_record = records[0];
        update_record.record_modify_time = "2024-05-20 20:00:00";
        
        if (db.updateQSO(update_record)) {
            std::cout << "成功更新QSO记录" << std::endl;
        } else {
            std::cerr << "更新QSO记录失败" << std::endl;
            return 1;
        }
    }
    
    // 断开数据库连接
    db.disconnect();
    std::cout << "测试完成" << std::endl;
    
    return 0;
}